export const state = {
    lat: '',
    lng: '',
    location:'未定位',
    themeColor: '#1A3387', //主题色
    recharge: {},
    withdraw: {},
    main: {},
    share: {},
    user: {},
    uEmpty: {},
    images: {},
    category: [],
    service: [],
}

export const getters = {
    themeColor: state => state.themeColor,
    lat: state => state.lat,
    lng: state => state.lng,
    location: state => state.location,
    initMain: state => state.main,
    initShare: state => state.share,
    initUser: state => state.user,
    initRecharge: state => state.recharge,
    initWithdraw: state => state.withdraw,
    uEmpty: state => state.uEmpty,
    images: state => state.images,
    category: state => state.category,
    service: state => state.service,
}

export const actions = {
    async mp_update({ dispatch, commit },isSet=false) {
        if (uni.canIUse("getUpdateManager")) {
            const updateManager = uni.getUpdateManager();
            updateManager.onCheckForUpdate(function (res) {
                // 请求完新版本信息的回调
                if (res.hasUpdate) {
                    updateManager.onUpdateReady(function () {
                        uni.showModal({
                            title: "更新提示",
                            content: "新版本已经准备好，是否重启应用？",
                            success: function (res) {
                                if (res.confirm) {
                                    // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                                    updateManager.applyUpdate();
                                }
                            }
                        });
                    });
                    updateManager.onUpdateFailed(function () {
                        // 新的版本下载失败
                        uni.showModal({
                            title: "更新提示",
                            content: "请您删除当前小程序，重新打开"
                        });
                    });
                }else if(isSet==true){
                    uni.$u.toast('已是最新版本');
                }
            });
        }
    },
    async getAppConfig({ dispatch }) {
        const result = await uni.$u.http.post('common/init');
        if (result.code === 1) {
            return result.data;
        }
        return false;
    },
    async initApp({ dispatch, commit }, options) {
        const result = await dispatch('getAppConfig');
        if (result) {
            commit('CONFIG', result);
            dispatch('getLoginByUnion');
        }
    },
}


export const mutations = {
	CONFIG(state, payload) {
		Object.keys(payload).forEach(k => {
			state[k] = payload[k];
		});
	},
    setOrderStatus(state,data){
        state.orderStatus = data;
    },
}


